home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9739 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.3 KB  |  38 lines

  1. Path: templar.fgi.net!bwendlin
  2. From: bwendlin@I_should_put_my_domain_in_etc_NNTP_INEWS_DOMAIN (Physics Lizard)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: HELP! Modifying the EOF in a file!
  5. Date: 13 Mar 1996 01:33:06 GMT
  6. Organization: FGInet, Inc., Springfield, IL
  7. Message-ID: <4i58ki$uoh@grail.fgi.net>
  8. References: <4i585k$4ia@news.netam.net>
  9. NNTP-Posting-Host: templar.fgi.net
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. The Bowling Green Connection inexplicably wrote:
  13. } I am having trouble shortening the size of a text file...
  14. } Suppose I have a text file with 3 lines of data, then I
  15. } run this program:
  16.  
  17. } void main() {
  18. }    FILE *dat;
  19. }    dat=fopen("file.txt", "r+");
  20. }    fprintf(dat, "Hello! %c", EOF);
  21. }    fclose(dat);
  22. } }
  23.  
  24. } Why doesn't the EOF character chop off the remaining two lines?
  25. } When I print out the file after running this program, the ONLY thing
  26. } that changed was the first few characters.. The other two lines
  27. } still remain..  HELP!
  28.  
  29. You are opening the file read only.  In order to do what you are 
  30. wanting, why don't you just open the file as write?  Then, everything
  31. in the file will be overwritten.
  32.  
  33. --
  34. Bill Wendling            bwendlin@fgi.net 
  35. GCS/M/S d s-:+ a? C++++$ UL++>++++ P+++>+++++ L+++>+++++ E--- W-- N++ !o
  36. !K w--- O M-- !V PS+++@ PE- Y !PGP t+++(*) 5-- X- R++ tv--- b+++ DI++++
  37. !D G+ e++>+++++ h(++) !r !y+
  38.